<?php

namespace App\Http\Controllers\Api;

use App\Model\Comment;
use App\Model\Orders;
use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;

class CommentController extends Controller
{
    /**
     * 查询评论订单信息
     */
    public function index(Request $request){
        $id = $request->input("ordersId");
        $order = new Orders();
        $ordersInfo = $order->select('a.num','a.id as orders_id','b.name','b.thumb_img','b.reprice','b.id as goods_id')
            ->leftJoin('orders_info as a','orders.id','=','a.orders_id')
            ->leftJoin('goods as b','a.goods_id','=','b.id')
            ->where('orders.id','=',$id)
            ->get();
        if(count($ordersInfo)>0){
            $this->success(array('data'=>$ordersInfo));
        }else{
            $this->error('暂无数据');
        }
    }

    /**
     *新增评论
     */
    public function addCommentInfo(Request $request){
        $comment = new Comment();
        $orders = new Orders();
        $ordersId = $request->input("orders_id");
        $ordersInfo = $orders->find($ordersId);
        $ordersInfo->status = 3;
        $result = $ordersInfo->save();
        $comment->content = $request->input("content");
        $comment->goods_id = $request->input("goods_id");
        $comment->user_id = $request->input("user_id");
        $res = $comment->save();
        if($res && $result){
            $this->success('添加成功');
        }else{
            $this->error('暂无数据');
        }
    }
}
